/*
 * StructureDTD.h
 *
 *  Created on: 22 mars 2011
 *      Author: lgu
 */

#ifndef STRUCTUREDTD_H_
#define STRUCTUREDTD_H_



#include <string>
#include <vector>
#include <fstream>

using namespace std;

//Entite = base
class DTDEntite
{
protected:

public:
	DTDEntite();
	bool isElement();
	bool isEnsemble();
	virtual ~DTDEntite();
	virtual string getAffichage();
};

//AppEntite = Entite + cardinalite
class AppEntite
{
private:
	DTDEntite* contenuAppEntite;
	int typeCardinalite;
		//type de cardinalite:
		//	0: pas de cardinalite
		//	1: _PLUS(+)
		//	2: _AST(*)
		//	3: _QMARK(?)

public:
	AppEntite();
	AppEntite(DTDEntite*, int);

	string getAffichage();


};


class DTDElement : public DTDEntite
{
private:
	string name;

public:
	DTDElement();
	DTDElement(string);
	virtual ~DTDElement();
	string getName();
	void setName(const string& pName) { name = pName; }

	virtual string getAffichage();
};


class DTDEnsemble : public DTDEntite
{
private:
	vector<AppEntite> sousEntites;
	vector<int> relations;
		//type de relation:
		//	0 : seg sed
		//	1 : seg,sed
		//	2 : seg|sed
		//	3?

public:
	DTDEnsemble();
	DTDEnsemble(const vector<AppEntite>&, const vector<int>&);
	virtual ~DTDEnsemble();
	void ajouterEntite(AppEntite, int);

	vector<AppEntite> getEntites();
	vector<int> getRelations();

	virtual string getAffichage();
};



//===================================================
class DTDPhrase
{
protected:

public:
	virtual ~DTDPhrase();
	DTDPhrase();
	virtual string getAffichage() = 0;
	bool isElement();
	bool isAttlist();
};


class DTDPhraseElement : public DTDPhrase
{
private:
	DTDElement elementCorr;
	int typeRelationCorr;
		//type de relationCorr:
		//	0 : un DTDEnsemble normal
		//	1 : _EMPTY
		//	2 : _ANY

	AppEntite ensembleCorr;

public:
	DTDPhraseElement();
	DTDPhraseElement(DTDElement, int);
	virtual ~DTDPhraseElement();
	bool ajouterEnsemble(DTDEnsemble, int unCord = 0);
	bool ajouterEnsemble(AppEntite ent);
	const AppEntite& getEntite() { return ensembleCorr; }
	string getAffichage();
	void setElementName(const string& name) { elementCorr.setName(name); }

};

struct DTDAttribute
{
  string name;
  string type;
  string defaultValue;

  DTDAttribute(string pname, string ptype, string pdefault) : name(pname), type(ptype), defaultValue(pdefault)
  {}
  
  string getAffichage() const
  {
      return name + " " + type + " " + defaultValue;
  }
};

class DTDPhraseAttlist : public DTDPhrase
{
private:
	string nomElem;
	vector<DTDAttribute> attributes;

public:
	DTDPhraseAttlist();
	DTDPhraseAttlist(const string& nomE);
	virtual ~DTDPhraseAttlist();
	void addAttribute(const DTDAttribute& attr);
	void setElementName(string name) { nomElem = name; }
	string getAffichage();

};


//========================================================
//========================================================

class StructureEntiteDTD
{
private:
	vector<DTDPhrase*> contenu;

public:
	StructureEntiteDTD();
	void ajouterPhrase(DTDPhrase*);

	string getAffichage();
};

#endif
